#include<stdio.h>
  #include<unistd.h>
  #include<fcntl.h>
  #include<stdlib.h>
  #include<errno.h>
  #include<string.h>
  #include<sys/stat.h>
  int main(){ 
      umask(0); //cancel system umask 
      //"w" = O_WRONLY(write file) + O_CREAT(create file) +  O_TRUNC (clean file)
      //"a" = O_WRONLY(write file) + O_CREAT(create file) +  O_APPEND (append file)
      //"r" = O_RDONLY(read file) 
      int fd = open("log.txt",O_RDONLY,0666);
	  if(fd<0){
		  perror("fd error");
		  exit(-1);
	  }
	  //dup2(fd,1 );   //output redirect
	  // printf("fd :%d\n", fd);   //printf -> stdout
	  // fprintf(stdout," fd :%d\n",fd);   //printf -> stdout
	  // fflush(stdout);
	  dup2(fd,0);      //input redirect
	  char str[128] = {0};
	  fgets(str,sizeof(str) -1 ,stdin);
	  printf("%s\n",str); 
      close(fd);
      return 0;
  }

